'''
Created on 2012-12-12

@author: levi
'''
import unittest

import time

from symbolic_state_space import SymbolicStateSpace

from t_core.matcher import Matcher

from symbolic_exec_patterns.HMatch_L2_SM2SM_S2SLHS import HMatch_L2_SM2SM_S2SLHS
from symbolic_exec_patterns.HMatch_L2_SM2SM_M2MLHS import HMatch_L2_SM2SM_M2MLHS
from symbolic_exec_patterns.HMatch_L2_MM2MM_M2M_1LHS import HMatch_L2_MM2MM_M2M_1LHS
from symbolic_exec_patterns.HMatch_L2_MM2MM_M2M_2LHS import HMatch_L2_MM2MM_M2M_2LHS

#from transformation_patterns_old.HL1_S2S import HL1_S2S
#from transformation_patterns_old.HL1_M2M import HL1_M2M
#from transformation_patterns_old.HL2_SM2SM import HL2_SM2SM
#from transformation_patterns_old.HL2_MM2MM import HL2_MM2MM
#from transformation_patterns_old.HL2_F2F import HL2_F2F
#
#
#class Test(unittest.TestCase):
#
#    def setUp(self):
#        self.backwardPatterns = {'HL1_S2S': None,
#                                 'HL1_M2M': None,                   
#                                 'HL2_SM2SM': [Matcher(HMatch_L2_SM2SM_S2SLHS()),Matcher(HMatch_L2_SM2SM_M2MLHS())],
#                                 'HL2_MM2MM': [Matcher(HMatch_L2_MM2MM_M2M_1LHS()),Matcher(HMatch_L2_MM2MM_M2M_2LHS())],
#                                 'HL2_F2F': None}
#
#    def test_one_layer_one_rule(self):
#        transformation = [[HL1_S2S()]]
#        rulesIncludingBackLinks = [[]]
#
#        nrStates = self._run(transformation, rulesIncludingBackLinks, self.backwardPatterns)  
#        self.assertEqual(nrStates,2)
#        
#    def test_one_layer_two_rules(self):
#        rulesIncludingBackLinks = [[]]
#        transformation = [[HL1_S2S(),HL1_M2M()]]
#
#        nrStates = self._run(transformation, rulesIncludingBackLinks, self.backwardPatterns)  
#        self.assertEqual(nrStates,4)
#
#    def test_two_layers_one_rule_second_layer(self):
#        transformation = [[HL1_S2S(), HL1_M2M()], [HL2_SM2SM()]]
#        rulesIncludingBackLinks = [[],[transformation[1][0]]]        
#
#        nrStates = self._run(transformation, rulesIncludingBackLinks, self.backwardPatterns)  
#        self.assertEqual(nrStates,5)
#        
#    def test_two_layers_two_rules_with_back_second_layer(self):
#        transformation = [[HL1_S2S(), HL1_M2M()], [HL2_SM2SM(), HL2_MM2MM()]]
#        rulesIncludingBackLinks = [[],[transformation[1][0],transformation[1][1]]]        
#
#        nrStates = self._run(transformation, rulesIncludingBackLinks, self.backwardPatterns)  
#        self.assertEqual(nrStates,8)
#        
#    def test_two_layers_three_rules_second_layer(self):
#        transformation = [[HL1_S2S(), HL1_M2M()], [HL2_SM2SM(), HL2_MM2MM(), HL2_F2F()]]
#        rulesIncludingBackLinks = [[],[transformation[1][0],transformation[1][1]]]        
#
#        nrStates = self._run(transformation, rulesIncludingBackLinks, self.backwardPatterns)  
#        self.assertEqual(nrStates,16)
#        
#    def test_two_layers_three_rules_first_layer(self):
#        transformation = [[HL1_S2S(), HL1_M2M(), HL2_F2F()], [HL2_SM2SM(), HL2_MM2MM()]]
#        rulesIncludingBackLinks = [[],[transformation[1][0],transformation[1][1]]]        
#
#        nrStates = self._run(transformation, rulesIncludingBackLinks, self.backwardPatterns)  
#        self.assertEqual(nrStates,16)
#
#    def _run(self, transformation, rulesIncludingBackLinks, backwardPatterns):
#        s = SymbolicStateSpace(transformation, rulesIncludingBackLinks, self.backwardPatterns)
#        t0 = time.time()
#        s.build_set()
#        t1 = time.time()
#        print '\n'
#        print '-----------------------------------------------'
#        print 'Built ' + str(len(s.symbStateSpace)) + ' states'         
#        print 'Done in: ' + str(t1 -t0)
#        self._print_states(s)
#        return len(s.symbStateSpace)
#    
#    def _print_states(self,s):
#        for state in s.symbStateSpace:
#            print "----------"
#            if state == ():
#                print 'Empty'
#            else:
#                for s in state:
#                    print s
#
#
#if __name__ == "__main__":
#    #import sys;sys.argv = ['', 'Test.testName']
#    unittest.main()